package com.qf.blog.controller;

import com.qf.blog.auth.LoginThreadLocal;
import com.qf.blog.entity.Comment;
import com.qf.blog.service.ICommentService;
import com.qf.blog.service.IDiscussPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.thymeleaf.model.IComment;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author toString
 * @since 2024-05-23
 */
@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private ICommentService commentService;

    @Autowired
    private IDiscussPostService postService;

    @RequestMapping("/add/{postId}")
    public String add(@PathVariable Integer postId , Comment comment){
        comment.setUserId(LoginThreadLocal.get().getId());
        comment.setStatus(0);
        comment.setCreateTime(new Date());
        commentService.save(comment);

        if(comment.getEntityType() == 1){
            postService.addComputeQueue(comment.getEntityId());
        }

        return "redirect:../../discussPost/info/"+postId;
    }
}
